package com.jidian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jidian.entity.User;
import com.jidian.mapper.UserMapper;
import com.jidian.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 冯永龙、王艳玲、李斐
 * @since 2020-11-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(User user) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_name",user.getUserName());
        wrapper.eq("pass_word",user.getPassWord());
        return this.userMapper.selectOne(wrapper);
    }

    @Override
    public List<User> getTeacher() {
        Map<String,Object> map = new HashMap<>();
        map.put("user_status",1);
        List<User> list = userMapper.selectByMap(map);
        return list;
    }

    @Override
    public List<User> getStudent() {
        Map<String,Object> map = new HashMap<>();
        map.put("user_status",0);
        List<User> list = userMapper.selectByMap(map);
        return list;
    }

    @Override
    public Boolean deleteUser(Integer id) {
        System.out.println(userMapper.deleteById(id));
        if (userMapper.deleteById(id)==0){
            return true;
        }else {
            return false;
        }

    }
}
